package com.firestone.service.center.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.firestone.bean.dto.menu.MenuDTO;
import com.firestone.bean.entity.mysql.primary.ImCenterMenu;
import com.firestone.dao.primary.center.ImCenterMenuDao;
import com.firestone.service.center.IImCenterMenuService;

/**
 * <p>
 * DM-center菜单表 服务实现类
 * </p>
 *
 * @author CAIYJ
 * @since 2018-03-26
 */
@Service
public class ImCenterMenuServiceImpl
        extends ServiceImpl<ImCenterMenuDao, ImCenterMenu>
        implements IImCenterMenuService {

    @Override
    public Page<MenuDTO> listMenu(Page<MenuDTO> page, String name)
            throws Exception {
        EntityWrapper<MenuDTO> ew = new EntityWrapper<>();
        ew.setEntity(new MenuDTO());
        ew.where(StringUtils.isNotBlank(name),
                "cm.`name` LIKE concat('%',{0},'%')", name);
        ew.orderBy("cm.update_time", false);
        List<MenuDTO> list = this.baseMapper.selectMenuList(page, ew);
        return page.setRecords(list);
    }

}
